#!/bin/sh

#  Name:        create_temps
#  Version:		0.3
#  Depends:		awk
#  Part Of:     linuxrules

#  Purpose:		Install time helper for reading appropriate
#               sensor entries and create library code
#               accordingly.
#  Goal:	   	REMOVING THIS COMPLETELY LETTING THE CODE
#               DO ITS THING.
#  Notes:       Perhaps pc entry 00:18.3 is shared for most
#               devices? :p
#  Creation:   	Fri Oct 15 2010
#  Modified:	Fri Oct 22 2010, 00:17:39
#  Insects:		Works fine but is a BUG itself.
#
#  Feel free to contact me at:
#  <http://sites.google.com/site/code933k>
#  in case of bugs, updates, proposals or comments

#  Copyright (C) 2010 Mario García H.
#
#  THIS PROGRAM IS FREE SOFTWARE:
#  Distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty
#  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#  You should have received a copy of the GNU GPL License
#  version 3 or superior along with this program.
#  If not, see: <http://www.gnu.org/licenses/gpl.txt>

cat <<EOF
#  Name:        temp_sensors
#  Version:     0.1
#  Part Of:     linuxrules

#  Description: Install-time dinamically created library
#               for reading PC temperature sensors.

#  Modified:    (see create sensors last modified date)
#  See COPYING for linuxrules GPL3 licensing info.

#  NOTICE:  THE GOAL IS REMOVING create_sensors.sh IF
#           YOU THINK YOU CAN, PLEASE DO OR TELL ME
#           YOUR IDEAS. THANKS.

BEGIN {
    sensor = 0
EOF

for sensor in $(find /sys -type f -name "temp[0-9]_input" -prune -path "*pci*")
do
    printf "\n\tgetline < \"${sensor}\"\n"
    printf "\tsensor++\n"
    printf "\t"
    echo '_sensors["TEMP", sensor] = int($0 / 1000)'
    printf "\tclose(\"${sensor}\")\n"
done

cat <<EOF
}
EOF

